// create by dplord at 2017-02-06 17:06

#include <iostream>
using namespace std;

/**
 * 指针函数①
 * @return
 */
int* a() {
    static int b = 12;
    return &b;
}

/**
 * 指针函数②
 * @return
 * 这里后面调用完了要手动释放
 */
int* a1() {
    int* a = (int *)malloc(sizeof(int));
    *a = 12;
    return a;
}

/**
 * 指针函数③
 * @return
 */
char* a2() {
    char* s = "hello";
    return s;
}


int add(int a, int b) {
    return a + b;
}

/**
 * 函数指针
 *
 * @param argc
 * @param argv
 * @return
 */


int main(int argc, char **argv) {
    //第1种指针函数
    int* num = a();
    cout << *num << "\n";

    //第2种指针函数
    int* num2 = a1();
    cout << *num2 << "\n";
    free(num2);

    //第3种指针函数
    char* s = a2();
    cout << s << endl;


    //定义函数指针
    int (*f)(int , int);
    f = add;

    cout << (*f)(1, 2) << "\n";

    char* s1 = "hello";
    char s2[] = "hello";

    //64位系统的指针都是占8字节, 32位是4字节
    cout << "sizeof(s1) = " << sizeof(s1) << "\n";
    //输出6, 字符串 + \0 结束符
    cout << "sizeof(s2) = " << sizeof(s2) << "\n";
    return 0;
}